﻿
@{
    ViewBag.Title = "ChangePassword";
}

<div class="container" style="min-height:500px;">

    <div class="row">
        <div class="col-xs-3">
            <ul class="nav default-sidenav">
                <li>
                    @Html.ActionLink("基本资料", "Setting", "Student", new { @class = "fa fa-cogs" })
                </li>
                <li class="active">
                    @Html.ActionLink("修改密码", "ChangePassword", "Student", new { @class = "fa fa-wrench" })
                </li>

            </ul>

        </div>
        <div class="col-xs-9">
            <div class="page-header">
                <h1><i class="fa fa-wrench"></i> 修改密码 </h1>
            </div>
            <div class="page-content row">
                <form class="form-horizontal" role="form" onsubmit="return false;">

                    <!-- password -->
                    <div class="form-group">
                        <label for="password" class="col-sm-2 control-label">密码</label>
                        <div class="col-sm-10">
                            <input type="password" class="form-control" id="password" placeholder="请输入密码">
                            <span style="display:none" class="glyphicon glyphicon-warning-sign form-control-feedback"></span>
                        </div>
                    </div>

                    <!-- password-confirm -->
                    <div class="form-group">
                        <label for="password-confirm" class="col-sm-2 control-label">再次输入密码</label>
                        <div class="col-sm-10">
                            <input type="password" class="form-control" id="password-confirm" placeholder="请输入密码">
                            <span style="display:none" class="glyphicon glyphicon-warning-sign form-control-feedback"></span>
                        </div>
                    </div>
   
                    <!-- Buttons -->
                    <div class="form-group">
                        <!-- Buttons -->
                        <div class="col-md-5 col-md-offset-2">
                            <button class="btn" id="btn-reg" onclick="changePassword()">
                                确认修改
                            </button>

                        </div>
                    </div>
                </form>
                <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                <h4 class="modal-title" id="myModalLabel">提示</h4>
                            </div>
                            <div class="modal-body" id="resultContent">
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">返回</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript">
    $("#password").change(change);
    $("#password-confirm").change(change);

    function change() {
        var input = $(this);
        if (input.val() != '') {
            input.parent().parent().removeClass('has-feedback');
            input.parent().parent().removeClass('has-warning');
            input.parent().children('span').hide();
        }
    }

    function validate(input) {
        if (input.val() != '')
            return true;
        input.parent().parent().addClass('has-feedback');
        input.parent().parent().addClass('has-warning');
        input.parent().children('span').show();
        return false;
    }

    function changePassword() {
        if (!validate($("#password")) || !validate($("#password-confirm")))
            return;
        var pwdConfirm = $("#password").val();
        var pwd = $("#password-confirm").val();
        if (pwdConfirm != pwd)
        {
            $("#password-confirm").addClass('has-warning');
            $("#resultContent").html("两次密码不一致");
            $('#myModal').modal('show');
            return;
        }
        $.ajax({
            url: '@Url.Action("ChangPassword","Account")',
            type: 'post',
            data: { password: pwd },
            error: function (result) {
                $("#resultContent").html(result.responseText);
                $('#myModal').modal('show');
            },
            success: function () {
                window.location.href = '@Html.Raw(Url.Action("Login","Account"))';
            }
        });
    }
</script>